<template>
    <div class="e-form">
        <BillTop title="年度采购预算登记变更新增" @cancel="handleClose"></BillTop>
        <div class="tabs">
            <div class="tabs-title">基本信息</div>
            <el-form ref="form" :model="form" label-width="200px">
                <el-row>
                    <!-- <el-col :span="12">
                        <el-form-item label="变更编号：">
                            <span>{{formData.planYearBudget.changeBillNo}}</span>
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="12">
                        <el-form-item label="变更日期：" prop="billDate">
                            <el-date-picker
                                v-model="formData.planYearBudget.billDate"
                                type="date"
                                placeholder="选择日期"
                                value-format="yyyy-MM-dd"
                                :clearable="false"
                            >
                            </el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="预算年度：">
                            <span>{{ formData.planYearBudget.year }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="预算编号：">
                            <span>{{ formData.planYearBudget.billNo }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="原预算总金额（元）：">
                            <span>{{ formData.planYearBudget.budgetAmount }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="变更后预算总金额（元）：">
                            <span>{{formData.planYearBudget.changeBudgetAmount}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="机构：">
                            <span>{{ formData.planYearBudget.orgName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="状态：">
                           <span>{{ statusLable(formData.planYearBudget.state) }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="变更人：">
                            <span>{{ formData.planYearBudget.founderName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="币种：">
                            <span>{{ formData.planYearBudget.currency }}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-form-item  label="备注：">
                        <el-input type="textarea" v-model="formData.planYearBudget.remarks" placeholder="请输入内容"></el-input>
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="本位币：">
                            <span>{{ formData.planYearBudget.baseCurName }}</span>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="人民币汇率：">
                            <span>{{formData.planYearBudget.rmbRate}}</span>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="本位币汇率：">
                            <span>{{formData.planYearBudget.baseCurRate}}</span>
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="12">
                        <el-form-item label="预算总金额（本位币）：">
                            <span>{{formData.planYearBudget.baseCurBudgetAmount}}</span>
                        </el-form-item>
                    </el-col> -->
                </el-row>
            </el-form>
        </div>
        <div class="buttons">
            <el-button
                type="primary"
                size="small"
                class="btn-blue"
                @click="preserve"
                v-debounce
                >保存</el-button
            >
            <el-button size="small" @click="handleClose" v-debounce>取消</el-button>
        </div>
    </div>
</template>

<script>
import { mapState } from 'vuex'
import '@/utils/jquery.scrollTo.min'
import request from '@/api/equip/equipPlan.js'
export default {
    data () {
        return {
            formData: {
                //基础信息
                'planYearBudget': {
                    'auditTime': '',
                    'auditor': '',
                    'auditorId': '',
                    'baseCurBudgetAmount': 0,
                    'baseCurId': '',
                    'baseCurName': '',
                    'baseCurRate': 0,
                    'billDate': '',
                    'billId': '',
                    'billNo': '',
                    'budgetAmount': 0,
                    'changeBillId': '',
                    'changeBillNo': '',
                    'changeBudgetAmount': 0,
                    'changeState': null,
                    'currency': '',
                    'currencyId': '',
                    'founderId': '',
                    'founderName': '',
                    'modifier': '',
                    'modifierId': '',
                    'nullifyCreated': '',
                    'nullifyCreator': '',
                    'nullifyCreatorId': '',
                    'nullifyDescription': '',
                    'nullifyReason': '',
                    'number': 0,
                    'orgId': '',
                    'orgName': '',
                    'recorder': '',
                    'recorderId': '',
                    'remarks': '',
                    'rmbId': '',
                    'rmbName': '',
                    'rmbRate': 0,
                    'rmbSumBudgetAmount': 0,
                    'state': 0,
                    'version': 0,
                    'workId': '',
                    'year': 0
                }

            },
            billid: this.$route.query.billid,
        }
    },
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm//币种
        }),
        //状态
        statusLable () {
            return param=> {
                const state =  this.$store.state.equip.equipData.state
                const obj = state.find(x=>+x.value === param)
                return (obj ?  obj.label :  '')
            }
        },
    },
    components: {
    },
    created () {
        this.userId = localStorage.getItem('userId')
        this.getInfo()
    },
    mounted () {

    },
    methods: {
        //基本信息查询
        getInfo () {
            const date = new Date()
            this.formData.planYearBudget.billDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
            const params = {
                planId: this.billid,
                userId: this.userId
            }
            request.getInitProcurementBaseInfo(params).then(res=>{
                this.formData.planYearBudget = res.planYearBudget
                this.formData.planYearBudget.billDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
                this.formData.planYearBudget.changeBillId = this.billid
                this.formData.planYearBudget.state = 0
            })
        },
        //保存
        preserve () {
            request.ProcureBaseInfoChangeAdd(this.formData.planYearBudget).then(res=>{
                this.clientPop('info', '保存成功!是否进行下一步操作？', ()=>{
                    this.$router.push({
                        path: '/procurementPlanChangeEdit',
                        query: {
                            billid: res,
                            name: 'planDetail'
                        }
                    })
                },
                null,
                this.handleClose
                )
            })
        },
        handleHistory () {
            this.$router.push({
                path: '/procurementPlanShow',
                query: {
                    billid: this.billid,
                    name: 'changeHistory'
                }
            })
        },
        //取消
        handleClose () {
            this.$router.replace('/procurementPlanList')
        },

    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.form {
    margin-top: 10px;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
</style>
